package com.lhl.blog.controller;

import com.lhl.blog.common.pojo.request.AddBlogInfoParam;
import com.lhl.blog.common.pojo.request.UpdateBlogInfoParam;
import com.lhl.blog.common.pojo.response.BlogInfoResponse;
import com.lhl.blog.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RequestMapping("/blog")
@RestController
public class BlogController {

    //注入的是接口的实现类，要改实现类的话，直接改这里的name的值就可以了
    //这里name的值是bean的名称，不是类名
    @Resource(name = "blogServiceImpl")
    private BlogService blogService;

    @GetMapping("/getList")
    public List<BlogInfoResponse> getList(){
        log.info("获取博客列表");
        return blogService.getList();
    }

    @GetMapping("/getBlogDetail")
    public BlogInfoResponse getBlogDetail(@NotNull Integer blogId){
        log.info("获取博客详情，blogId：{}",blogId);

        return blogService.getBlogDetail(blogId);
    }

    @PostMapping("/add")
    public Boolean addBlog(@Validated @RequestBody AddBlogInfoParam param){
        log.info("添加博客，接收到参数param：{}",param);
        return blogService.addBlog(param);
    }

    @PostMapping("/update")
    public Boolean updateBlog(@Validated @RequestBody UpdateBlogInfoParam param){
        log.info("更新博客，接收到参数param{}",param);
        return blogService.updateBlog(param);
    }

    @PostMapping("/delete")
    public Boolean deleteBlog(@NotNull Integer blogId){
        log.info("删除博客，接收到参数blogId：{}",blogId);
        return blogService.deleteBlog(blogId);
    }


}
